﻿#include "global.h"

#include "cocos2d.h"
#include "Tank0.h"
#include "MyMain.h"
#include "Levels.h"
#include "Water.h"
bool global_difficult=false;
CCSize global_winSize=CCSizeMake(420,700);
bool global_sound=true;
Tank0 *global_myTank=NULL;
MyMain *global_instance=NULL;
int map_levelScore[] = {0, 0, 0,0};
CCDictionary *map_wallArr=NULL;//new  CCMutableDictionary<int,Wall*>();//
CCArray *map_tankArr=NULL;//new CCMutableArray<Tank*>();

char tmpbuffer[100];
int map_score = 0;
int map_life =NUMLIFE;
bool map_isPlay = false;
bool map_over = false;
int map_leave=0;
//bool map_reStart = false;
int map_level = 1;
int map_location[] = {192+16, 16, 384+16};
int map_map1[26][26];//=new int[26][26];
//int global_tank0num = 0;
bool global_tank0god;
int global_nowScore = 0;
float global_shotLevel =INIT_SHOTLEVEL;
//bool global_bonusdie = false;
int global_tank1num = 0;
//bool global_isBomb = true;
bool global_run = true;
Levels levels;
void map_allInit()
{
	//map_life = 1;
	map_score = 0;
	map_leave = map_total;
	//map_reStart = false;
	global_run = true;
	global_shotLevel = INIT_SHOTLEVEL;
	global_tank1num=0;
    if(map_wallArr==NULL) map_wallArr=new  CCDictionary();
	else map_wallArr->removeAllObjects();
    if (map_tankArr==NULL) map_tankArr=new CCArray();
  	else map_tankArr->removeAllObjects();
}
int global_oppose(int dir)
{
	switch (dir)
	{
	case 1:
		return 2;
	case 2:
		return 1;
	case 3:
		return 4;
	case 4:
		return 3;
	}
	return 0;
}

bool global_hitRect(cocos2d::CCPoint p1a , cocos2d::CCPoint p1b,cocos2d::CCPoint  p2a,cocos2d::CCPoint p2b)
{
	float minx = p1a.x > p2a.x ? p1a.x : p2a.x;
	float maxx = p1b.x < p2b.x ? p1b.x : p2b.x;
	float miny = p1a.y > p2a.y ? p1a.y : p2a.y;
	float maxy = p1b.y < p2b.y ? p1b.y : p2b.y;

	if (minx <= maxx && miny <= maxy)
		return true;
	else
		return false;
}
bool global_overlapsSprite(CCSprite* the,CCSprite* bon)
{
	CCRect a=CCRectMake(the->getPosition().x-the->getContentSize().width/2,the->getPosition().y-the->getContentSize().height/2,the->getContentSize().width,the->getContentSize().height);
	CCRect b=CCRectMake(bon->getPosition().x-bon->getContentSize().width/2,bon->getPosition().y-bon->getContentSize().height/2,bon->getContentSize().width,bon->getContentSize().height);
	return global_hitRect(a.origin,ccp(a.origin.x+a.size.width,a.origin.y+a.size.height),b.origin,ccp(b.origin.x+b.size.width,b.origin.y+b.size.height));
}
bool global_overlaps(CCRect a,CCRect b)
{
	return global_hitRect(a.origin,ccp(a.origin.x+a.size.width,a.origin.y+a.size.height),b.origin,ccp(b.origin.x+b.size.width,b.origin.y+b.size.height));
}
void drawRect(CCRenderTexture*m_target,CCPoint p1,CCPoint p3,ccColor4F color)
{

	m_target->begin();
	::glLineWidth(2);
    CCPoint pts[4];
    pts[0].x=p1.x;
    pts[0].y=p1.y;
    pts[1].x=p1.x;
    pts[1].y=p3.y;
    pts[2].x=p3.x;
    pts[2].y=p3.y;
    pts[3].x=p3.x;
    pts[3].y=p1.y;
	
    ::ccDrawSolidPoly(pts,4,color);//
	m_target->end();
}

